#!/bin/bash

# chmod +x start.sh  dos2unix start.sh
# 设置输出语言
export LANG=en_US.UTF-8

cd /usr/local/application/duiduo-gateway

#输出信息
echo "<<<<<<<<<<<<<<<<<<<<<<<<begin>>>>>>>>>>>>>>>>>>>>>>>>"

#获取当前服务器时间，并格式化
dqtime=$(date "+%Y-%m-%d %H:%M:%S")

#输出当前服务器时间
echo "datetime: ${dqtime}"

echo "===================>docker rm -f duiduo-gateway-duiduo-gateway-1"
docker rm -f duiduo-gateway-duiduo-gateway-1

echo "===================>docker rmi duiduo-gateway-duiduo-gateway:latest"
docker rmi duiduo-gateway-duiduo-gateway:latest

echo "<<<<<<<<<<<<<<<<<<<<<<<<docker remove>>>>>>>>>>>>>>>>>>>>>>>>"

echo "===================>git pull"
git pull

echo "===================>mvn clean package -Dmaven.test.skip=true"
export JAVA_HOME=/usr/local/jdk/jdk-17.0.12
mvn clean package -Dmaven.test.skip=true

echo "<<<<<<<<<<<<<<<<<<<<<<<<end>>>>>>>>>>>>>>>>>>>>>>>>"

#输出友好的倒计时提示，项目在5秒钟后启动
seconds_left=5
echo "Start the project after 5 seconds"
while [ $seconds_left -gt 0 ];
do
   echo -n "Please wait for> ${seconds_left} <seconds.."
   sleep 1
   seconds_left=$(($seconds_left - 1))
   #清除上一行内容，即上一个倒计时输出的信息
   echo -ne "\r     \r"
done

echo "===================>docker-compose up -d"
docker-compose up -d

# 输出日志
#docker logs -f duiduo-gateway-duiduo-gateway-1
